import 'package:flutter/material.dart';
import 'package:flutter_widget/custom/custom_appbar.dart';

// ignore: must_be_immutable
class PopMenuButtonPage extends StatefulWidget {
  String name;
  PopMenuButtonPage({Key? key, required this.name}) : super(key: key);

  @override
  // ignore: no_logic_in_create_state
  _PopMenuButtonPageState createState() => _PopMenuButtonPageState();
}

class _PopMenuButtonPageState extends State<PopMenuButtonPage> {
  String currentValue = 'quarter';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: Center(
        child: Column(
          children: [
            Text(currentValue),
            PopupMenuButton(
                onSelected: (value) {
                  // ignore: avoid_print
                  print(value);
                  setState(() {
                    currentValue = value as String;
                  });
                },
                itemBuilder: (BuildContext context) => [
                      const PopupMenuItem(
                        value: 'year',
                        child: Text('年份'),
                      ),
                      const PopupMenuItem(
                        value: 'quarter',
                        child: Text('季度'),
                      ),
                      const PopupMenuItem(
                        value: 'month',
                        child: Text('月份'),
                      ),
                    ])
          ],
        ),
      ),
    );
  }
}
